<?php

namespace Action\Widget;

class SearchResults extends \Library\Action\UserAction 
	implements \Library\Action\AjaxAction {

	private $_results = array();
	
	public function execute() {
		parent::execute();
		
		$search = $this->getParam( 'search' );
		
		$fullName = 'CONCAT(first_name, CONCAT( \' \', last_name))';
		
		$results = _q()->searchN( 'users',
			array( 
				'first_name',
				'last_name',
				$fullName
			),
			$search, $fullName, 0, 5 );
		foreach( $results as $result ) {
			$user = \Bean\User::getUser( $result );
			$this->_results[] = new \Library\Widget\SearchResult\UserResult( $user );
		}
		
	}
	
	public function getResults() {
		return $this->_results;
	}
}
